import SimpleHTTPServer

class HTTPRequestHandler(SimpleHTTPServer.SimpleHTTPRequestHandler):
	def do_POST(self):
		import functions
		
		length=int(self.headers.getheader('content-length'))
		rawPost=self.rfile.read(length)
		self.fnName=self.path[1:]
		
		try:
			callFunction=getattr(functions, self.fnName)
		except:
			callFunction=self.badFunction
						
		content=callFunction(rawPost,self.headers)

		self.send_response(200)
		self.send_header("Content-type", 'text/plain')
		self.send_header("Content-Length", len(content))
		self.end_headers()
		
		#output file object .write()
		self.wfile.write(content)
		
	def badFunction(self, *k):
		return "Oops, you should probably fix something (%s)...." % self.fnName